var kx = [40.484991998000055, 40.594887314000054];
var ky = [115.72965078900006, 115.87801871800002];

function toRad(d) {  return d * Math.PI / 180; }

function getFlatternDistance(lat1, lng1, lat2, lng2) {
    var dis = 0;
    var radLat1 = toRad(lat1);
    var radLat2 = toRad(lat2);
    var deltaLat = radLat1 - radLat2;
    var deltaLng = toRad(lng1) - toRad(lng2);
    var dis = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(deltaLat / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(deltaLng / 2), 2)));
    return dis * 6378137;
};

var kilxi = getFlatternDistance(kx[0], ky[0], kx[1], ky[0]); //纬度 南北间距
var kilyi = getFlatternDistance(kx[0], ky[0], kx[0], ky[1]); //经度 东西间距

console.log(kilxi);
console.log(kilyi);

var kilxz = Math.ceil(kilxi / 1000);
var kilyz = Math.ceil(kilyi / 1000);

console.log("南北"+kilxz);
console.log("东西"+kilyz);

var kxn = kx[1] - kx[0]; //实际纬度差
var kyn = ky[1] - ky[0]; //实际经度差

var kilxv = (kxn / kilxi) * [Math.ceil(kilxi / 1000) * 1000];//宽
var kilyv = (kyn / kilyi) * [Math.ceil(kilyi / 1000) * 1000];//高

kx[1] = kx[0] + kilxv;
ky[1] = ky[0] + kilyv;

var kilxs = [kx[0], kx[1]];
var kilys = [ky[0], ky[1]];

kilxs = [40.484991998000055, 40.594887314000054];
kilys = [115.72965078900006, 115.87801871800002];

var ooooo = GPS.gcj_encrypt(kilxs[0], kilys[0]);
var ppppp = GPS.gcj_encrypt(kilxs[1], kilys[1]);

var qqqq = GPS.bd_encrypt(ooooo.lat,ooooo.lon);
var wwww = GPS.bd_encrypt(ppppp.lat,ppppp.lon);

kilys = [qqqq.lon,wwww.lon];
kilxs = [qqqq.lat,wwww.lat];
console.log(kilxs);
console.log(kilys);
/*
console.log(kilxs);
console.log(kilys);

var kilxiqq = getFlatternDistance(39.5, 115.9, 40.6, 115.9); //纬度 南北间距
var kilyiqq = getFlatternDistance(39.5, 115.9, 39.5,116.8); //经度 东西间距
*/


// [115.75092438500008,
//     40.51354561200003]




